#ifndef MYSCENE_H
#define MYSCENE_H

#include <QMainWindow>

#include "util/env.h"
#include "util/appevent.h"
#include "Geo/map/geomap.h"

#include <QRegExpValidator>

#include <QAction>
#include <QMainWindow>
#include <QMenu>
#include <QMenuBar>
#include <QToolBar>
#include <QToolButton>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QDockWidget>
#include <map>
#include <set>

#include "Dialog/viewlogdialog.h"
#include "Widget/layerstreewidget.h"
#include "Widget/openglwidget.h"
#include "Widget/OpenGLWidget3D.h"

#include "View/filetreeview.h"
#include "Widget/dbtreewidget.h"
#include "SQL/sqloperator.h"
#include "Dialog/statistics/statisticfielddialog.h"
#include "Dialog/tools/settingdialog.h"
#include "Dialog/protable/addfielddialog.h"
#include "Dialog/protable/deletefielddialog.h"

enum CoordUint
{
    kDegree = 0,
    kMeter = 1,
    kKiloMeter = 2
};

QT_BEGIN_NAMESPACE
namespace Ui { class MyScene; }
QT_END_NAMESPACE

class MyScene : public QMainWindow
{
    Q_OBJECT

public:
    MyScene(QWidget *parent = nullptr);
    ~MyScene();
public:
    void iniCatalog();
    void iniStatusBar();
    void setUnit(CoordUint unit);
    void showMsg(const QString& msg, int timeMs = 0);

    void iniToolBar();
    void iniAction();
    void iniMainWindow();
    void iniWidget();
    void iniMenuBar();
    // void iniPanle();

    void readProTableFeatureLayer(GeoFeatureLayer* featureLayer);
signals:
    void sigUpdateOpengl();

public slots:
    void onStartEditing(bool on);
public slots:
    // set theme
    void onSetDarkTheme();
    void onSetLightTheme();
    //stausBar
    void onUpdateCoord(double x, double y);
    void onUpdateProTable(GeoLayer* layer);
    //mainToolBar
    void onRotate();
    void onCursorNormal();
    void onCursorEditing();
    void onCursorPalm();
    void onCursorWhatIsThis();
    //meusBar
    void onNewMap();

    void onOpenGeoShapefile();
    void onOpenTiff();

    void onShowLogDialog();
    void onAbout();
    void onAddField(QString fieldName, GeoFieldType fieldType);
    void onDeleteField(int fieldIndex);
    void onSelectRows();

public slots:
    //-->Field Operator
    void on_actExportCSV_triggered();
    void on_actExportTXT_triggered();
    void on_actExportExcel_triggered();
    void on_actAddField_triggered();
    void on_actDeleteField_triggered();
    void on_actStatisticField_triggered();
    void on_actSetting_triggered();
    void on_actDrawPoint_triggered();
    void on_actDrawLineString_triggered();
    void on_actDrawPolygon_triggered();

protected:
    virtual void closeEvent(QCloseEvent*) override;
private:
    // mainwindow layout
    // TabWidget
    QDockWidget* dockTabWidget;
    QHBoxLayout* layoutTabWidget;
    QTabWidget* tabWidget;
    QWidget* pageProTable;
    QTableWidget* propertyTable;
    QHBoxLayout* layoutPageProTable;

    //LayerTree
    QDockWidget* dockLayerTree;
    LayersTreeWidget* layersTreeWidget;
    QHBoxLayout* layoutDockLayerTree;
    //OpenGLWidget
    OpenGLWidget* openGLWidget;
    OpenGLWidget3D* openglWidget3D;
    QHBoxLayout* layoutCentralWidget;
    //Catalog
    QDockWidget *dockCatalog;

private:
    // toolBar layout
    QToolBar* toolbarMouseCursor;
    QToolBar* toolbarEditLayer;
    // toolBar action-->mouseCursor
    QAction* actCursorNormal;
    QAction* actCursorEditing;
    QAction* actCursorPalm;
    QAction* actCursorWhatIsThis;
    // toolBar action-->editLayer
    QComboBox* comboCurLayer;
    QComboBox* comboCurEditStatus;

private:
    // stautuBar layout
    QLabel* labelCoord;
    QLabel* labelUnit;
    CoordUint unit = kDegree;

private:
    // menuBar layout
    QMenu* fileMenu;          //File
    QMenu* openFileMenu;      //File-->Open Files
    QMenu* newFileMenu;       //File-->New File
    QMenu* connectDBMenu;     //File-->Connect Database
    QMenu* recentFilesMenu;   //File-->Recent File
    QMenu* editMenu;          //Edit
    QMenu* analyseMenu;       //Analyse
    QMenu* toolsMenu;         //Tools
    QMenu* drawMenu;          //Draw
    QMenu* windowMenu;        //Window
    QMenu* helpMenu;          //Help
    QMenu* fieldMenu;         //Field
    // Right clicked menu
    QMenu* popMenu;
    // menuBar action
    // -->File
    QAction* actOpenShapfile; //File-->Open Files-->Shapfile
    QAction* actOpenTiff;
    QAction* actNewMap;
    QAction* actNewLayer;
    QAction* actConnectMySQL; //File-->Connect Database-->MySQL

    //-->Help
    QAction* actShowLog;
    QAction* actAbout;

    //-->Analyse
    QAction *actStatisticField;
    QAction *actSetting;
    //-->Draw
    QAction *actDrawPoint;
    QAction *actDrawLineString;
    QAction *actDrawPolygon;
    /*
    //-->View
    QAction *actOrthographic;
    QAction *actPerspective;
    QAction *actOrthoPerspect;
    */
    //-->Field Operator
    QAction *actExportCSV;
    QAction *actExportTXT;
    QAction *actExportExcel;
    QAction *actAddField;
    QAction *actDeleteField;

    QLineEdit* editRotate;
    QAction* rotateAction;
private:
    // dialog
    ViewLogDialog* viewLogDialog;
private:
    //ToolBar
    GeoMap *&map;
private:
    Ui::MyScene *ui;
};
#endif // MYSCENE_H
